package com.secret.chain.secretchain.service.impl;

import com.secret.chain.secretchain.domain.entity.Comment;
import com.secret.chain.secretchain.mapper.CommentMapper;
import com.secret.chain.secretchain.result.Result;
import com.secret.chain.secretchain.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public Result queryByArticleId(Integer id) {
        Comment comment = commentMapper.queryByArticleId(id);
        return Result.success(comment);
    }

    @Override
    public Result queryByUserId(Integer id) {
        Comment comment = commentMapper.queryByUserId(id);
        return Result.success(comment);
    }

    @Override
    public Result save(Comment comment) {
        LocalDateTime now = LocalDateTime.now();
        comment.setCreateTime(now);
        comment.setUpdateTime(now);
        comment.setStatus(1);
        commentMapper.insert(comment);
        return Result.success();
    }

    @Override
    public Result delete(Integer id) {
        commentMapper.delete(id);
        return Result.success();
    }

    @Override
    public Result update(Comment comment) {
        LocalDateTime now = LocalDateTime.now();
        comment.setUpdateTime(now);
        commentMapper.update(comment);
        return Result.success();
    }
}
